﻿package mortal.game.view.ranking.view
{
    import __AS3__.vec.*;
    import com.mui.controls.*;
    import com.mui.utils.*;
    import flash.events.*;
    import mortal.game.events.*;
    import mortal.game.mvc.*;
    import mortal.mvc.core.*;

    public class RankingFirstInfoSpr extends GSprite
    {
        private var _rankData:Array;
        private var _rankingDataVec:Vector.<RankingFirstInfoCell>;
        private var _currSelCell:RankingFirstInfoCell;

        public function RankingFirstInfoSpr()
        {
            this._rankData = new Array();
            this._rankingDataVec = new Vector.<RankingFirstInfoCell>;
            return;
        }// end function

        override protected function createDisposedChildrenImpl() : void
        {
            super.createDisposedChildrenImpl();
            this.createItems();
            this.configEventListener(MouseEvent.CLICK, this.onClickHandler);
            return;
        }// end function

        private function createItems() : void
        {
            var _loc_1:int = 0;
            var _loc_2:RankingFirstInfoCell = null;
            _loc_1 = 0;
            while (_loc_1 < 6)
            {
                
                _loc_2 = UICompomentPool.getUICompoment(RankingFirstInfoCell);
                _loc_2.x = 225 * int(_loc_1 % 2);
                _loc_2.y = 167 * int(_loc_1 / 2);
                this.addChild(_loc_2);
                this._rankingDataVec.push(_loc_2);
                this.pushUIToDisposeVec(_loc_2);
                _loc_2.bg = _loc_1 + 1;
                _loc_1++;
            }
            return;
        }// end function

        private function initFirstInfo() : void
        {
            Dispatcher.dispatchEvent(new DataEvent(EventName.RankingGetFirstInfo));
            return;
        }// end function

        public function set data(param1:Object) : void
        {
            var _loc_2:* = param1 as Array;
            this._rankData = _loc_2;
            var _loc_3:int = 0;
            while (_loc_3 < _loc_2.length)
            {
                
                this._rankingDataVec[_loc_3].data = this._rankData[_loc_3];
                _loc_3++;
            }
            if (_loc_2.length < 6)
            {
                _loc_3 = _loc_2.length;
                while (_loc_3 < 6)
                {
                    
                    this._rankingDataVec[_loc_3].data = null;
                    _loc_3++;
                }
            }
            return;
        }// end function

        private function onClickHandler(event:MouseEvent) : void
        {
            var _loc_2:RankingFirstInfoCell = null;
            if (event.target is RankingFirstInfoCell)
            {
                if (this._currSelCell == event.target)
                {
                    return;
                }
                for each (_loc_2 in this._rankingDataVec)
                {
                    
                    if (event.target == _loc_2)
                    {
                        _loc_2.isSelected = true;
                        Dispatcher.dispatchEvent(new DataEvent(EventName.RankingLookRoleInfo, _loc_2.rankingData));
                        this._currSelCell = event.target as RankingFirstInfoCell;
                        continue;
                    }
                    _loc_2.isSelected = false;
                }
            }
            return;
        }// end function

        override protected function disposeImpl(param1:Boolean = true) : void
        {
            super.disposeImpl(param1);
            this._currSelCell = null;
            this._rankingDataVec.length = 0;
            return;
        }// end function

    }
}
